package game.web.controller;

import game.web.base.Constants;
import game.web.dao.dto.ChargeDTO;
import game.web.entity.ChargeEntityManager;
import game.web.struts.ChargeForm;

import java.util.ArrayList;
import java.util.List;

import projectx.core.base.ProjectXSystemException;
import projectx.core.base.ProjectXUserException;
import projectx.transaction.TransactionHandler;
import projectx.web.base.ConstantsProjectX;
import projectx.web.base.ProjectXDbTrxController;
import projectx.web.base.ProjectXForm;
import projectx.web.base.UserContext;

public class ChargeListControllor extends ProjectXDbTrxController {

	protected ChargeListControllor(UserContext uc, ProjectXForm form) {
		super(uc, form);
	}

	@Override
	public Object execute() throws ProjectXUserException,
			ProjectXSystemException {

		debugBegin();

		UserContext uc = getUc();
		ChargeForm form = (ChargeForm)getForm();
		
		System.out.println("ChargeListControllor+form.startdate="+form.getStartdate());
		
		String id = (String) uc.get(ConstantsProjectX.USER_ID);
		String startdate = form.getStartdate();
		String enddate = form.getEnddate();
		List<ChargeDTO> list = new ArrayList();
		if(startdate==null||enddate==null||startdate==""||enddate=="")
			list = ChargeEntityManager.listById(id);
		else
			list = ChargeEntityManager.listByDate(id,startdate,enddate);		
		
		uc.put(Constants.CHARGE_LIST_CHARGE_TO_LIST, list);

		debugEnd();
		return null;
	}

	public static Object execute(UserContext uc, ProjectXForm form)
			throws ProjectXUserException, ProjectXSystemException {
		return TransactionHandler.call(new ChargeListControllor(uc, form));
	}
}
